#include "PlayerMoves.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>

void resetPlayerMoves(PlayerMoves &pm) {
	pm.actual_x = -1;
	pm.actual_y = -1;
	pm.player_number = -1;
	pm.remote_round_number = -1;
	pm.active_state = PLAYER_STATE_DISABLED;

	for (int i = 0; i < PLAYER_MAX_MOVES_NUMBER; ++i)
	{
		pm.last_directions[i] = SNAKE_UP;
	}
}

std::string debugPlayerMoves(PlayerMoves * p_moves) {
	std::string to_ret = "";
	std::ostringstream temp_num_x, temp_num_y, temp_num_player,
			temp_num_round;

	to_ret += "^^^^^^^^^^^^^#PLAYER_MOVES#^^^^^^^^^^^^^^^^^^^^^\n";
	to_ret += "Actual X:";
	temp_num_x << p_moves->actual_x;
	to_ret += temp_num_x.str();
	to_ret += "\n";

	to_ret += "Actual Y:";
	temp_num_y << p_moves->actual_y;
	to_ret += temp_num_y.str();
	to_ret += "\n";

	to_ret += "Player number:";
	temp_num_player << p_moves->player_number;
	to_ret += temp_num_player.str();
	to_ret += "\n";

	to_ret += "Remote round number:";
	temp_num_round << p_moves->remote_round_number;
	to_ret += temp_num_round.str();
	to_ret +="\n";

	to_ret += "Active state: ";
	switch (p_moves->active_state)
	{
	case PLAYER_STATE_DISABLED:
		to_ret += "DISABLED";
		break;
	case PLAYER_STATE_ACTIVE:
		to_ret += "ACTIVE";
		break;
	case PLAYER_STATE_GAME_WIN:
		to_ret += "PLAYER_STATE_GAME_WIN";
		break;
	case PLAYER_STATE_GAME_LOST:
		to_ret += "PLAYER_STATE_GAME_LOST";
		break;
	default:
		to_ret +=" ERROR!!!";
	}
	to_ret += "\n";

	to_ret += "MOVES::";
	for (int i = 0; i < PLAYER_MAX_MOVES_NUMBER; ++i)
	{

		if (SNAKE_UP == p_moves->last_directions[i])
		{
			to_ret += "SNAKE_UP";
		}
		if (SNAKE_DOWN == p_moves->last_directions[i])
		{
			to_ret += "SNAKE_DOWN";
		}
		if (SNAKE_LEFT == p_moves->last_directions[i])
		{
			to_ret += "SNAKE_LEFT";
		}
		if (SNAKE_RIGHT == p_moves->last_directions[i])
		{
			to_ret+= "SNAKE_RIGHT";
		}
		to_ret += ",";
	}

	to_ret += "\n";

	return to_ret;

}


